
//************************************************************************************************
//         determina: navegador, version y sistema operativo
        
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

                

//*********************fin: determina: navegador, version y sistema operativo***************************************************************************
    
    function esInteger(e){       
        //alert ("CharCode: " + e.keyCode);               
        if (BrowserDetect.browser=='Explorer'){
             var charCode         
             charCode = e.keyCode               
             if ( (charCode >= 48 && charCode <= 57) || charCode == 8 || charCode == 0 ) {           
                return true;
             }
             else{                 
                return false;
             }
        }else{               
              var nav4 = window.Event ? true : false;
              var key = nav4 ? e.which : e.keyCode;         
              return (!(key > 31 && (key < 48 || key > 57)));
        }
        
    }  
	
	   function esDecimal(e){
         var charCode         
         charCode = e.keyCode
         if (BrowserDetect.browser=='Explorer'){
			 if ( (charCode >= 48 && charCode <= 57) || charCode == 8 || charCode == 0 || charCode == 46) {
				return true;
			 }
			 else{      
				//alert("Por favor teclee solo n�meros en este campo!");
				//alert ("CharCode: " + charCode);            
				return false;
			 }
	      }else{
			  var nav4 = window.Event ? true : false;
              var key = nav4 ? e.which : e.keyCode;
              return ((!(key > 31 && (key < 48 || key > 57))) || key == 46);
			  }  
	    }  
      

function login(){

	usu=document.getElementById('usuario').value;
	passw=document.getElementById('clave').value;	

	if (!validarBlanco('usuario', 'Ingrese su usuario.', 'error')){ return;}
	if (!validarBlanco('clave', 'Ingrese su clave.', 'error')){ return;}

	document.location='../Usuarios/validar_login.php?loginname='+usu+'&clave='+passw;

}
function adm_login(){

	usu=document.getElementById('usuario').value;
	passw=document.getElementById('clave').value;
	
	if (!validarBlanco('usuario', 'Ingrese su usuario.', 'error')){ return;}
	if (!validarBlanco('clave', 'Ingrese su clave.', 'error')){ return;}
	document.frm.submit();

}
function confirmarAltaUsuario(accion){	
	var usuario=document.getElementById('usuario').value;
	var nombre=document.getElementById('nombre').value;
	var apellido=document.getElementById('apellido').value;
	var direccion=document.getElementById('direccion').value;
	var numero=document.getElementById('numero').value;
	var apto=document.getElementById('apto').value;
	var telefono=document.getElementById('telefono').value;
	var celular=document.getElementById('celular').value;
	var email=document.getElementById('email').value;

	if (!validarBlanco('usuario','Ingrese su nombre de usuario.', 'error')){ return;}
	if (!validarBlanco('nombre', 'Ingrese su nombre nombre.', 'error')){ return;}
	if (!validarBlanco('apellido', 'Ingrese su Apellido.', 'error')){ return;}	
	if (!esFormatoEmail('email', 'Ingrese un e-mail válido.', 'error')){ return;}
        
        if (accion=='INS'){
            var clave=document.getElementById('clave').value;
            if (!validarBlanco('clave', 'Ingrese su clave.', 'error')){ return;}
            document.location='../Usuarios/INSUsuario.php?usuario='+usuario+'&clave='+clave+'&nombre='+nombre+'&apellido='+apellido+'&direccion='+direccion+'&telefono='+telefono+'&email='+email+'&numero='+numero+'&apto='+apto+'&celular='+celular;
        }else{
            document.location='../Usuarios/UPDUsuario.php?usuario='+usuario+'&clave='+clave+'&nombre='+nombre+'&apellido='+apellido+'&direccion='+direccion+'&telefono='+telefono+'&email='+email+'&numero='+numero+'&apto='+apto+'&celular='+celular;
        }

}

function mostrarError(id_div, mensajeError, id_div_error){ 
	//document.getElementById('error').innerHTML=document.getElementById('msgError').value;
	document.getElementById(id_div_error).innerHTML=mensajeError;
    document.getElementById(id_div).style.backgroundColor="#FFFFCC"; 
      //document.getElementById(id_div).style.color="#d32e12";
}

function sacarError(id_div, id_div_error){ 	
    document.getElementById(id_div).style.backgroundColor="#FFFFFF"; 
    document.getElementById(id_div_error).innerHTML='';
}

function validarBlanco(id_div_a_validar, mensajeError, id_div_error){
	valor=document.getElementById(id_div_a_validar).value;
	if (valor==''){
		mostrarError(id_div_a_validar, mensajeError, id_div_error);
		return false;
	}else{
		sacarError(id_div_a_validar, id_div_error);
		return true;
	}
}
	

function esFormatoEmail(id_div_a_validar, mensajeError, id_div_error){
    if (!validarBlanco('email', 'Ingrese su e-mail.', 'error')){ return;}
	valor=document.getElementById(id_div_a_validar).value;	
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (filter.test(valor)){
	 	    sacarError(id_div_a_validar, id_div_error);
	        return true;	        
		}else{           
        	mostrarError(id_div_a_validar, mensajeError, id_div_error);
	    	return false;
	    	
	    }
} 

function mostrarOcultarObjeto(idControl, Mostrar){                     
            elem = document.getElementById(idControl);
            if (Mostrar=='1' || Mostrar=='True' || Mostrar=='true'){
                elem.style.display='block';               
            }else{
                elem.style.display='none';
            }
}

